import CodoBase from "../../lib/CodoBase";
import { hc } from "../../lib/hc/hc";
import HCHttpService from "../../lib/hc/http";
import HCMQTTService from "../../lib/hc/mqtt";
import HCWanService from "../../lib/hc/wan";

export default class HikvisionISC extends CodoBase {
	/** 直接提供总的海清管理类 */
	HttpService = HCHttpService;

	HCMQTTService = HCMQTTService;

	HCWanService = HCWanService;

	/** 获取 海清 http 主服务实例
	 * - 主服务上挂载了所有子服务
	 */
	getHttpServiceInstance(device: hc.http.device) {
		return new HCHttpService(device, this.app);
	}

	getMQTTServiceInstance(topic: string) {
		return new HCMQTTService(topic, this.app);
	}

	/**
	 * 针对每个设备的wan操作实例，可以仅获取单例
	 */
	getWanServiceInstance(device: hc.http.device, isSingleton = true) {
		if (isSingleton) {
			if (!this[device.deviceId]) {
				this[device.deviceId] = new HCWanService(device, this.app);
			}
			return this[device.deviceId] as HCWanService;
		}
		return new HCWanService(device, this.app);
	}
}
